#ifndef _vs1053_H_
#define _vs1053_H_
												   
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_spi.h"
#include "stm32f10x_rcc.h"

/* Private define ------------------------------------------------------------*/
#define SPI_SPEED_HIGH    1  
#define SPI_SPEED_LOW     0

#define DREQ_PIN GPIO_Pin_2
#define DCS_PIN GPIO_Pin_0
#define CCS_PIN GPIO_Pin_12
#define RES_PIN GPIO_Pin_1
#define SCK_PIN GPIO_Pin_13
#define MISO_PIN GPIO_Pin_14
#define MOSI_PIN GPIO_Pin_15

#define SPI_PORT GPIOB

/* reset */
#define MP3_Reset(x)	  x ? GPIO_SetBits(GPIOA,RES_PIN) : GPIO_ResetBits(GPIOA,RES_PIN)
#define MP3_CCS(x)	  x ? GPIO_SetBits(SPI_PORT,CCS_PIN) : GPIO_ResetBits(SPI_PORT,CCS_PIN)
#define MP3_DCS(x)	  x ? GPIO_SetBits(GPIOA,DCS_PIN) : GPIO_ResetBits(GPIOA,DCS_PIN)
#define MP3_DREQ          GPIO_ReadInputDataBit(GPIOA,DREQ_PIN)


#define VS_WRITE_COMMAND 	0x02
#define VS_READ_COMMAND 	0x03

/* vs1053јДґжЖч¶ЁТе */
#define SPI_MODE        	0x00   
#define SPI_STATUS      	0x01   
#define SPI_BASS        	0x02   
#define SPI_CLOCKF      	0x03   
#define SPI_DECODE_TIME 	0x04   
#define SPI_AUDATA      	0x05   
#define SPI_WRAM        	0x06   
#define SPI_WRAMADDR    	0x07   
#define SPI_HDAT0       	0x08   
#define SPI_HDAT1       	0x09 
#define SPI_AIADDR      	0x0a   
#define SPI_VOL         	0x0b   
#define SPI_AICTRL0     	0x0c   
#define SPI_AICTRL1     	0x0d   
#define SPI_AICTRL2     	0x0e   
#define SPI_AICTRL3     	0x0f

//SCI_MODE register bits as of p.38 of the datasheet
#define SM_DIFF                                     0x0001
#define SM_LAYER12                                  0x0002
#define SM_RESET                                    0x0004
#define SM_CANCEL                                   0x0008
#define SM_EARSPEAKER_LO                            0x0010
#define SM_TESTS                                    0x0020
#define SM_STREAM                                   0x0040
#define SM_EARSPEAKER_HI                            0x0080
#define SM_DACT                                     0x0100
#define SM_SDIORD                                   0x0200
#define SM_SDISHARE                                 0x0400
#define SM_SDINEW                                   0x0800
#define SM_ADPCM                                    0x1000
#define SM_B13                                      0x2000
#define SM_LINE1                                    0x4000
#define SM_CLK_RANGE                                0x8000

//SCI_CLOCKF register bits as of p.42 of the datasheet
#define SC_ADD_NOMOD                                0x0000
#define SC_ADD_10x                                  0x0800
#define SC_ADD_15x                                  0x1000
#define SC_ADD_20x                                  0x1800
#define SC_MULT_XTALI                               0x0000
#define SC_MULT_XTALIx20                            0x2000
#define SC_MULT_XTALIx25                            0x4000
#define SC_MULT_XTALIx30                            0x6000
#define SC_MULT_XTALIx35                            0x8000
#define SC_MULT_XTALIx40                            0xA000
#define SC_MULT_XTALIx45                            0xC000
#define SC_MULT_XTALIx50                            0xE000

// Extra Parameter in X memory (refer to p.58 of the datasheet)
#define para_chipID_0                               0x1E00
#define para_chipID_1                               0x1E01
#define para_version                                0x1E02
#define para_config1                                0x1E03
#define para_playSpeed                              0x1E04
#define para_byteRate                               0x1E05
#define para_endFillByte                            0x1E06




/* Private function prototypes -----------------------------------------------*/
void vs1053_Init(void);
void vs1053_SetVol(void);
void vs1053_Reset(void);
void vs1053_SineTest(void);
void vs1053_SoftReset(void);
void vs1053_Record_Init(void);
void vs1053_ResetDecodeTime(void);
uint8_t vs1053_SPI_ReadWriteByte( uint8_t TxData );
uint16_t vs1053_GetDecodeTime(void);
void vs1053_WriteData( uint8_t * buf);
void vs1053_WriteReg( uint8_t reg,uint16_t value );
uint16_t vs1053_ReadReg( uint8_t reg); 
#endif

/*********************************************************************************************************
      END FILE
*********************************************************************************************************/

